package com.woniuxy.boot.nb_feedback.controller.pc;

import com.woniuxy.boot.common.bean.EsFeedback;
import com.woniuxy.boot.common.dto.EsFeedbackSearchDTO;
import com.woniuxy.boot.common.dto.FeedbackDTO;
import com.woniuxy.boot.common.pojo.ResponseResult;
import com.woniuxy.boot.common.util.JwtUtil;
import com.woniuxy.boot.common.vo.DisposeVO;
import com.woniuxy.boot.nb_feedback.feign.FeedbackSearchFeign;
import com.woniuxy.boot.nb_feedback.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("pc/dispose")
public class DisposeController {
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private FeedbackSearchFeign feedbackSearchFeign;

    /**
     * 按条件查询筛选反馈
     * @param feedbackSearch
     * @return
     */
    @PostMapping("getFeedbackByWrapper")
    public ResponseResult<List<EsFeedback>> getFeedbackByWrapper(@RequestBody EsFeedbackSearchDTO feedbackSearch) {
        return new ResponseResult<>(feedbackSearchFeign.getFeedback(feedbackSearch));
    }

    /**
     * 管理员根据反馈的id进行处理
     **/
    @PostMapping("disposeFeedback")
    public ResponseResult<Void> disposeFeedback(@RequestBody DisposeVO disposeVO, @RequestHeader("token") String token) {
        disposeVO.setAdminId(JwtUtil.parseJwt(token));
        feedbackService.disposeFeedback(disposeVO);
        return ResponseResult.SUCCESS;
    }

    /**
     * 查询所有的反馈
     * @return
     */
    @GetMapping("getAllFeedback")
    public List<FeedbackDTO> getAllFeedback(){
       return feedbackService.getAllFeedback();
    }
}
